home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / 302_01.zip / NO.C < prev    next >
Text File  |  1993-04-09  |  2KB  |  65 lines

  1. /* Create new object
  2.  
  3.    Copyright (c) 1988 by Gus O'Donnell
  4.  
  5.    Revision history:
  6.  
  7.    Version 1.00         February 29, 1988       As released.
  8.  
  9.    Version 1.01         March 20, 1988          Created libraries for all
  10.                                                 memory models
  11.  
  12. */
  13. #include <3d.h>
  14. #include <alloc.h>
  15. #include <float.h>
  16. #include <math.h>
  17. #include <stdio.h>
  18. #include <values.h>
  19.  
  20. int     new_obj (OBJECT *this_obj)
  21.  
  22. /* Create a new obj.  The initial data structure looks like this:
  23.  
  24.  
  25.                OBJECT o o------>FACE o X
  26.                       |              |
  27.                       V           +--+
  28.                    VERTEX o       |
  29.                           |       V
  30.                       +---+     FACE X
  31.                       |
  32.                    VERTEX X
  33.  
  34.  
  35. Where 'X' is the NULL pointer.  The value returned is 0 if the operation
  36. is successful, 1 otherwise. */
  37.  
  38. {
  39.     int count;
  40.     FACE *fhandle1,*fhandle2;       /* Handles for head and tail nodes of
  41.                                        FACE list */
  42.     VERTEX *vhandle1,*vhandle2;     /* Handles for head and tail nodes of
  43.                                        VERTEX list */
  44.  
  45.     /* Allocate memory.  Return a 1 if unsuccessful. */
  46.  
  47.     if (!(fhandle1 = (FACE *)malloc(sizeof(FACE)))) return(1);
  48.     if (!(fhandle2 = (FACE *)malloc(sizeof(FACE)))) return(1);
  49.     if (!(vhandle1 = (VERTEX *)malloc(sizeof(VERTEX)))) return(1);
  50.     if (!(vhandle2 = (VERTEX *)malloc(sizeof(VERTEX)))) return(1);
  51.     this_obj -> faces = fhandle1;
  52.     fhandle1 -> next = fhandle2;
  53.     fhandle1 -> first = NULL;
  54.     fhandle2 -> first = NULL;
  55.     fhandle2 -> next = NULL;
  56.     this_obj -> vertices = vhandle1;
  57.     vhandle1 -> next = vhandle2;
  58.     vhandle2 -> next = NULL;
  59.     for (count = 0;count < DIM;count++)  /* Put pseudodata in end nodes */
  60.     {
  61.         vhandle1 -> coord [count] = -MAXDOUBLE;
  62.         vhandle2 -> coord [count] =  MAXDOUBLE;
  63.     }
  64.     return(0);
  65. }